const path = require('path');
const { ANALYZE } = process.env;

module.exports = {
  distDir: '__next',
  webpack: (config, { dev }) => {
    console.log(config.entry)
    config.module.rules.push(
      {
        test: /\.css/,
        loader: 'emit-file-loader',
        options: {
          name: 'dist/[path][name].[ext]'
        }
      },
      {
        test: /\.css$/,
        use: ['babel-loader', 'raw-loader', 'postcss-loader']
      }
    );

    // 分析
    if (ANALYZE) {
      const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
      config.plugins.push(new BundleAnalyzerPlugin({
        analyzerMode: 'server',
        analyzerPort: 5888,
        openAnalyzer: true
      }));
    }

    return config;
  }
}
